package com.kylin.upms.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.kylin.upms.biz.entity.Role;
import com.kylin.upms.biz.entity.UserRole;
import com.kylin.upms.biz.mapper.UserMapper;
import com.kylin.upms.biz.mapper.UserRoleMapper;
import com.kylin.upms.biz.service.IUserRoleService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mht
 * @since 2019-04-11
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Autowired
    UserRoleMapper userRoleMapper;

    @Transactional
    @Override
    public void save(List<UserRole> list) {
        EntityWrapper<UserRole> wrapper = new EntityWrapper<UserRole>();
        wrapper.setEntity(new UserRole());
        wrapper.where("uid={0}",list.get(0).getUid());
        userRoleMapper.delete(wrapper);
        userRoleMapper.insertBatch(list);
    }
}
